﻿using System;
using System.Collections.Generic;
using Microsoft.TeamFoundation.VersionControl.Client;
using NLog;

namespace TfsGiggle.Core
{
    /// <summary>
    /// Workitemtracking services
    /// </summary>
    public static class TfsWorkItem
    {
        private static Logger _logger = LogManager.GetCurrentClassLogger();

        /// <summary>
        /// Isolated due to VersionControl.Client
        /// </summary>
        /// <param name="item"></param>
        /// <param name="workItems"></param>
        public static void AddWorkItems(Changeset item, Dictionary<int, string> workItems)
        {
            _logger.Trace("Changeset:{0}", item.ChangesetId);
            try
            {
                foreach (var workItem in item.WorkItems)
                {
                    if (!workItems.ContainsKey(workItem.Id))
                    {
                        workItems.Add(workItem.Id, workItem.Title);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Exception caught", ex);
            }
        }
    }
}